package io.flash.rpc.protocol;

import com.alibaba.fastjson.parser.Feature;

public enum CommandPacketClass {
    RPC_REQUEST(1, RpcRequestPacket.class),

    RPC_RESPONSE(2, RpcResponsePacket.class);


    CommandPacketClass(int command, Class<?> clazz) {
        this.command = (byte) command;
        this.clazz = clazz;
    }

    byte command;
    Class<?> clazz;


    public static byte getCommand(Class<?> aClass) {

        for (CommandPacketClass commandPacketClass : values()) {
            if (aClass == commandPacketClass.clazz) {
                return commandPacketClass.command;
            }
        }

        return 0;
    }

    public static Class<?> getPacketClass(byte command) {
        for (CommandPacketClass commandPacketClass : values()) {
            if (command == commandPacketClass.command) {
                return commandPacketClass.clazz;
            }
        }
        return null;
    }
}
